package com.tang.functions;

import com.tang.bean.WaterSensor;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.util.Collector;

/**
 * 扁平化转换实现类
 *
 * @author tang
 * @since 2023/6/7 11:02
 */
public class FlatMapFunctionImpl implements FlatMapFunction<WaterSensor, String> {

    @Override
    public void flatMap(WaterSensor value, Collector<String> out) throws Exception {
        if ("s1".equals(value.getId())) {
            // 如果是 s1，输出 vc
            out.collect(value.getVc().toString());
        } else if ("s2".equals(value.getId())) {
            // 如果是 s2，分别输出ts和vc
            out.collect(value.getTs().toString());
            out.collect(value.getVc().toString());
        }
    }

}
